<template>
  <div>
    <my-header :showBack="true" title="修改个人信息"></my-header>
    <div>
      <!-- 暂时不用 -->
      <div class="personal_info">
        <van-cell-group>
          <van-field v-model="userInfo.customerPhone"  label="电话号码" :disabled="true"/>
          <van-field v-model="userInfo.realName"  label="真实姓名" :disabled="disabledInput"/>
          <van-field v-model="userInfo.customerCard"   label="身份证号" :disabled="disabledInput"/>
          <van-field v-model="userInfo.customerName"   label="用户昵称" icon="clear" @click-icon="userInfo.customerName  = ''"/>
          <van-field v-model="userInfo.customerAlipay" label="支付宝号" icon="clear" @click-icon="userInfo.customerAlipay  = ''" />
          <van-field v-model="userInfo.bankName"       label="开户银行" icon="clear" @click-icon="userInfo.bankName  = ''" />
          <van-field v-model="userInfo.bankCard"       label="银行卡号" icon="clear" @click-icon="userInfo.bankCard  = ''" />        
        </van-cell-group>
      </div>
      <div class="footer_btn">
        <van-button type="primary" size="large" @click="confirm">确认修改</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import header from "@/components/header";

export default {
name: "modifyMsg",
  data() {
    return {
      userInfo:{},
      disabledInput:false
    };
  },
  components: {
    "my-header": header
  },
  created() {
    let customerInfo = JSON.parse(localStorage.getItem('userInfo'));
    this.userInfo = {
      customerName:customerInfo.customerName||'',
      realName:customerInfo.realName||'',
      customerCard:customerInfo.customerCard||'',
      customerPhone:customerInfo.customerPhone||'',
      customerAlipay:customerInfo.customerAlipay||'',
      bankName:customerInfo.bankName||'',
      bankCard:customerInfo.bankCard||'',
      // email:customerInfo.email||''
    }
    if(this.userInfo.customerCard){
      this.disabledInput = true;
    }
  },
  methods: {
    confirm() {
      if (this.userInfo.realName.length < 2 || this.userInfo.realName.length > 10) {
        Toast({ message: "请输入2-10位真实姓名", position: "bottom" });
        return;
      }
      if (!this.$validator.isIdCard(this.userInfo.customerCard)) {
        Toast({ message: "请输入正确的身份证号", position: "bottom" });
        return;
      }
      if (this.userInfo.customerName.length < 2 || this.userInfo.customerName.length > 10) {
        Toast({ message: "请输入2-10位用户昵称", position: "bottom" });
        return;
      }
      if (!this.$validator.isPhone(this.userInfo.customerAlipay)) {
        Toast({ message: "请输入正确的支付宝号", position: "bottom" });
        return;
      }
      if (this.userInfo.bankName=='') {
        Toast({ message: "请输入开户银行", position: "bottom" });
        return;
      }
      if (!this.$validator.isBankNo(this.userInfo.bankCard)) {
        Toast({ message: "银行卡号必须为16或19位数字", position: "bottom" });
        return;
      }else if(!this.$validator.bankNoCheck(this.userInfo.bankCard)){
        Toast({ message: "请输入真实有效的银行卡号", position: "bottom" });
        return;
      }

      this.$ajax(this.$api.modifyCustomerInfo, this.userInfo).then(res => {
        if (res.code === 0) {
          Toast({ message: "修改成功", position: "bottom" });
          this.goBack();
        }
      });
    }
  }
};
</script>

<style scoped>
.personal_info{
  margin: 5px 0;
}
/* .personal_info .van-cell {
  border-bottom: 6px solid #f4f4f4;
} */
.personal_info .btn{
  width:80%;
  background: #26a2ff;
  margin-top:50px;
  margin-left: 10%;
  box-shadow: none;
  border-radius: 5px;
  color:#fff;
  font-size:16px;
}
</style>

